package com.aaa.controller;

import com.aaa.dao.FUserMapper;
import com.aaa.service.FUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wsc.entity.FUser;
import com.aaa.service.UserService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("fuser")
public class FUserController {
    @Resource
    FUserMapper fUserMapper;
    @Resource
    UserService userService;
    @Resource
    FUserService fUserService;
    @RequestMapping("login")
    public List<FUser> select(String username, String password){
        return userService.login(username);
    }
    @RequestMapping("select")
    public Object select(Integer id){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("id",id );
        return fUserMapper.selectList(queryWrapper);
    }
    @RequestMapping("delete")
    public Integer delete(Integer id){
        return fUserMapper.deleteById(id);
    }
    @RequestMapping("insert")
    public boolean insert(FUser fUser){
       fUser.setPassword( new BCryptPasswordEncoder().encode(fUser.getPassword()));
       fUser.setState(0);
        fUser.setRid(1);
    return fUserService.save(fUser);
    }
    @RequestMapping("update")
    public Integer update(FUser fUser){
        return fUserMapper.updateById(fUser);
    }
}
